package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import easier.app.x.CommonCode;
import easier.app.x.view.EditInputManager;
import easier.recycler.BaseViewHolder;
import easier.recycler.MultiTypeAdapter;
import easier.recycler.TypeViewHolder;
import java.util.ArrayList;
import java.util.List;

public class MainActivity73 extends AppCompatActivity {

    private static final String TAG = "MainActivity73";

    private RecyclerView mRecycler;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity73.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main73 );
        initView();
    }

    private void initView() {

        mRecycler = (RecyclerView) findViewById( R.id.recycler );
        mRecycler.setLayoutManager( new LinearLayoutManager( this ) );
        mRecycler.setAdapter( new MultiTypeAdapter( convert() ) );
    }

    private List< TypeViewHolder > convert() {

        ArrayList< TypeViewHolder > list = new ArrayList<>();

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 1;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputChineseNumber( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "汉字和数字" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( EditInputManager.checkNumber( text ) ) {
                            CommonCode.showToast( v.getContext(), "不能全是数字" );
                        } else {
                            Log.d( TAG, "onClick: 符合" );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 2;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputSfz( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "身份证" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkSfz( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                        } else {
                            Log.d( TAG, "onClick: 符合" );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 3;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputMobile( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "手机号" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkMobile( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 4;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputNumber( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "数字" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkNumber( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 5;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputChineseName( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "中文名字" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkChineseName( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 6;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputChinese( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "中文字符" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkChinese( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 7;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputEmailAddress( editText, 50 );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "邮箱地址" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkEmailAddress( text ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 8;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputNumberDecimal( editText, 6 );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "小数(限制小数位数)" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                    }
                } );
            }
        } );

        list.add( new BaseViewHolder( R.layout.item_02 ) {

            @Override
            public int getType() {

                return 9;
            }

            @Override
            protected void onViewCreate( View view ) {

                super.onViewCreate( view );

                EditText editText = (EditText) view.findViewById( R.id.input );
                EditInputManager.setInputAddressStyle0( editText );
            }

            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > p ) {

                ((TextView) root.findViewById( R.id.title )).setText( "地址类型" );
                EditText editText = (EditText) root.findViewById( R.id.input );

                root.findViewById( R.id.check ).setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick( View v ) {

                        CharSequence text = editText.getText();
                        if ( !EditInputManager.checkChineseNumberLetter( text, "()（）#" ) ) {
                            CommonCode.showToast( v.getContext(), "验证失败" );
                            Log.d( TAG, "onClick: 不符合:" + text );
                        } else {
                            Log.d( TAG, "onClick: 符合:" + text );
                        }
                    }
                } );
            }
        } );

        return list;
    }
}